const { query } = require("../db/mysql");

async function queryUserByUsernameAndPassword(username, password) {
  const resp = await query(
    "select * from user where username = ? and password = ?",
    [username, password]
  );
  return resp[0];
}

async function queryUserByTel(tel) {
  const resp = await query("select * from user where tel = ?", [tel]);
  return resp[0];
}

async function queryUserByTelAndTelCode(tel, telCode) {
  const resp = await query("select * from user where tel = ? and telCode = ?", [tel, telCode]);
  return resp[0];
}

async function updateCodeByTel(tel, telCode) {
  const resp = await query(`UPDATE user SET telCode = ? WHERE tel = ?;`, [
    telCode,
    tel,
  ]);
  return resp;
}

module.exports = {
  queryUserByUsernameAndPassword,
  queryUserByTel,
  updateCodeByTel,
  queryUserByTelAndTelCode
};
